﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "GmStructure.h"
#include "IEditModeBehavior.h"
#include "GbmpQuickCast.h"

namespace gcmp
{
    class GM_STRUCTURE_EXPORT IStructureEditModeBehavior : public IEditModeBehavior
    {
        DEFINE_CAST_DERIVED(gcmp::IStructureEditModeBehavior,gcmp::IEditModeBehavior)
    public:
        virtual ~IStructureEditModeBehavior() {};

    public:
        virtual void SetEditingFamilyId(ElementId id) = 0;
        virtual ElementId GetEditingFamilyId() const = 0;

        virtual void SetEditingInstanceTypeId(ElementId instanceTypeId) = 0;
        virtual ElementId GetEditingInstanceTypeId() const = 0;

        virtual void SetPresetElementId(ElementId id) = 0;
        virtual ElementId GetPresetElementId() const = 0;

    protected:
        //子类须在结束编辑模式时将预设Element删除
        virtual void DeletePresetElementId(IDocument* pDoc) = 0;
    };
}

#define DECLARE_BASE_EDIT_MODE_BEHAVIOR_METHODS \
    public: \
    virtual bool IsNotAffectedByViewRange(const IElement* pElement) const override;

#define DEFINE_BASE_EDIT_MODE_BEHAVIOR_METHODS(CLASS_NAME) \
    bool CLASS_NAME::IsNotAffectedByViewRange(const IElement* pElement) const {return true;}


#define DECLARE_STRUCTURE_EDIT_MODE_BEHAVIOR_METHODS \
    DECLARE_BASE_EDIT_MODE_BEHAVIOR_METHODS \
    public: \
    virtual void SetEditingFamilyId(ElementId id) override; \
    virtual ElementId GetEditingFamilyId() const override; \
    virtual void SetEditingInstanceTypeId(ElementId instanceTypeId) override; \
    virtual ElementId GetEditingInstanceTypeId() const override; \
    virtual void SetPresetElementId(ElementId id) override; \
    virtual ElementId GetPresetElementId() const override;

#define DEFINE_STRUCTURE_EDIT_MODE_BEHAVIOR_METHODS(CLASS_NAME) \
    DEFINE_BASE_EDIT_MODE_BEHAVIOR_METHODS(CLASS_NAME) \
    void CLASS_NAME::SetEditingFamilyId(ElementId id){SetEditingFamilyId__(id);} \
    ElementId CLASS_NAME::GetEditingFamilyId() const {return GetEditingFamilyId__();} \
    void CLASS_NAME::SetEditingInstanceTypeId(ElementId instanceTypeId) {SetEditingInstanceTypeId__(instanceTypeId);} \
    ElementId CLASS_NAME::GetEditingInstanceTypeId() const {return GetEditingInstanceTypeId__();} \
    void CLASS_NAME::SetPresetElementId(ElementId id) \
    { \
        DBG_WARN_AND_RETURN_VOID_UNLESS(!GetPresetElementId__().IsValid(), L"预设参数对象未及时清理",L"GDMPLab",L"2024-03-30"); \
        SetPresetElementId__(id); \
    } \
    ElementId CLASS_NAME::GetPresetElementId() const{return GetPresetElementId__();}